package com.example.studentportrait.controller.admin;

import com.example.studentportrait.domain.ResponseResult;
import com.example.studentportrait.domain.dto.AnnouncementDto;
import com.example.studentportrait.domain.dto.AnnouncementListDto;
import com.example.studentportrait.domain.dto.ListUserDto;
import com.example.studentportrait.domain.entity.Announcement;
import com.example.studentportrait.service.AnnouncementService;
import com.example.studentportrait.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AnnouncementController {

    @Autowired
    AnnouncementService announcementService;

    /**
     * 公告分页查询
     * @param pageNum
     * @param pageSize
     * @param announcementListDto
     * @return
     */
    @GetMapping("/announcementList")
    public ResponseResult adminList(Integer pageNum, Integer pageSize, AnnouncementListDto announcementListDto){
        return announcementService.announcementList(pageNum,  pageSize,  announcementListDto);
    }

    /**
     * 新增公告
     * @param announcementDto
     * @return
     */
    @PostMapping("/addAnnouncement")
    public ResponseResult addAnnouncement(@RequestBody AnnouncementDto announcementDto) {
        Announcement announcement = BeanCopyUtils.copyBean(announcementDto, Announcement.class);
        return announcementService.addAnnouncement(announcement);
    }

    /**
     * 删除公告
     * @param id
     * @return
     */
    @DeleteMapping("/deleteAnnouncement/{id}")
    public ResponseResult deleteAnnouncement(@PathVariable("id") Long id){
        return announcementService.deleteAnnouncement(id);
    }

    /**
     * 批量删除公告
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteAnnouncementIds")
    public ResponseResult deleteAnnouncementIds(@RequestBody List<Long> ids){
        return announcementService.deleteAnnouncementIds(ids);
    }

    /**
     * 更新公告
     * @param announcement
     * @return
     */
    @PutMapping("/updateAnnouncementById")
    public ResponseResult<Announcement> updateAnnouncementById(@RequestBody Announcement announcement){
        return announcementService.updateAnnouncementById(announcement);
    }

}
